<?php

namespace app\index\controller;

use app\index\controller\Base;
use think\Db;
use think\Session;

class Mart extends Base
{
    /**
     * 市场统计首页
     * @return mixed
     */
    public function Index()
    {

        return $this->fetch('Index');
    }

    /**
     * 会员列表
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function UserList(){

        //等级名称
        $LevelName = Param('level_name');
        $this->assign('LevelName',$LevelName);

        //等级信息
        $LevelInfo = LevelInfo(['name'=>$LevelName]);



        //找出自己线下且对应等级的用户
        $Contact = Db::name('user_contact')->where(['contact_id'=>Session::get('user_id'),'layer'=>array('gt',0)])->select();
        $IdArray = [];
        foreach ($Contact as $k=>$v){
            $IdArray[] = $Contact[$k]['user_id'];
        }

        //用户数量
        $Count = UserCount(['level'=>$LevelInfo['id'],'status'=>1,'id'=>array('in',$IdArray)]);
        $this->assign('Count',$Count);
        //用户信息
        $UserList = UserList(['level'=>$LevelInfo['id'],'status'=>1,'id'=>array('in',$IdArray)]);

        foreach($UserList['UserList'] as $k=>$v){
            $Str1 = substr($UserList['UserList'][$k]['phone'] , 0 , 3);
            $Str2 = substr($UserList['UserList'][$k]['phone'] , -4);
            $UserList['UserList'][$k]['phone'] = $Str1.'****'.$Str2;
        }
        $this->assign('UserList',$UserList['UserList']);

        //分页
        $this->assign('Page',$UserList['Page']);

        return $this->fetch('UserList');
    }
}
